import { accountApi } from '@/apis'
import type { AccountItem } from '@/apis/accountTypes'
import { useDialog } from '@/hooks'

type Params = {
  refresh: PromiseFunc
}

export function useDisable({ refresh }: Params) {
  const { showConfirm } = useDialog()

  function handleDisable(item: AccountItem) {
    showConfirm({
      content: `确认${item.deleteFlag === 0 ? '禁用' : '启用'}该账号？`,
      async onOk() {
        await refresh(async () => {
          await accountApi.disableAccount(item.id, item.deleteFlag == 1 ? 0 : 1)
        })
      }
    })
  }

  return {
    handleDisable
  }
}
